#include "ogrebindingPCH.h"
#include "camerabinding.h"
#include "renderwindowbinding.h"

namespace lua_ogre {
const char* RenderWindowClassName = "RenderWindow";

LuaRenderWindow::LuaRenderWindow(Ogre::RenderWindow *window) : c_obj(window) {}

LuaRenderWindow::~LuaRenderWindow()
{}

const char* LuaRenderWindow::GetName() const
{
	if (c_obj)
	{
		return c_obj->getName().c_str();
	}

	return "Invalid RenderWindow";
}

static int AddViewPort(Ogre::RenderWindow *window, lua_State *ls)
{
	if (lua_gettop(ls) != 1
		|| !luaL_checkudata(ls, 1, CameraClassName))
	{
		LogLuaError << "RenderWindow:AddViewPort(camera) failed, invalid parameter!";
		return 0;
	}

	window->addViewport(((LuaCamera*)lua_touserdata(ls, 1))->c_obj);
	return 0;
}

static int RenderWindowAlloc(lua_State *ls)
{
	LogLuaError << "call ov.CreateRenderWindow() instead!";
	return 0;
}

static LuaMethod<Ogre::RenderWindow> g_rw_methods_and_props[] =
{
	{"AddViewPort", AddViewPort, 0, 0},
	{0, 0, 0, 0}
};

void BindRenderWindow(lua_State *ls)
{
	typedef LuaClassBind<Ogre::RenderWindow, LuaRenderWindow> RWBind;

	LuaTypeObject<Ogre::RenderWindow> type_obj(
		RenderWindowClassName,
		g_rw_methods_and_props,
		RenderWindowAlloc,
		RWBind::Dealloc,
		RWBind::ToString,
		RWBind::Thunk);

	RWBind::Register(ls, "ov", type_obj);
}

}